<script>
	import Vue from 'vue'
	import Cache from '@/utils/cache';
	export default {
		globalData: {
			pid: 0,
			code: 0,
		},
		onLaunch: function() {
			this.getSystemInfo();
			this.getUserInfo();
			this.getConfig();
		},
		onShow() {
			const queryData = uni.getEnterOptionsSync(); // uni-app版本 3.5.1+ 支持
			console.log(queryData);
			if (queryData.query.spread) {
				this.$Cache.set('spread', queryData.query.spread);
				this.globalData.pid = queryData.query.spread;
			}
			if (queryData.query.spid) {
				this.$Cache.set('spread', queryData.query.spid);
				this.globalData.pid = queryData.query.spid;
			}
			this.globalData.code = queryData.scene;
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			getUserInfo(){
				// #ifdef MP-WEIXIN
				// 微信版本更新
				if (wx.canIUse('getUpdateManager')) {
					const updateManager = wx.getUpdateManager()
					if (updateManager && updateManager.onCheckForUpdate) {
						updateManager.onCheckForUpdate(function(res) {
							// 请求完新版本信息的回调
							if (res.hasUpdate) {
								updateManager.onUpdateReady(function() {
									wx.showModal({
										title: '更新提示',
										content: '新版本已经准备好，是否重启应用？',
										success: function(res) {
											if (res.confirm) {
												updateManager.applyUpdate()
											}
										}
									})
								})
								updateManager.onUpdateFailed(function() {
									wx.showModal({
										title: '已经有新版本了哟~',
										content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
									})
								})
							}
						})
					}
				} else {
					wx.showModal({
						title: '提示',
						content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
					})
				}
				// #endif
				
				// 设置登录信息
				const token = uni.getStorageSync("token")
				if (token) {
					const userInfo = uni.getStorageSync("userInfo")
					this.$store.commit('user/setToken', token)
					this.$store.commit('user/setUserInfo', userInfo)
				}
			},
			getSystemInfo(){
				uni.getSystemInfo({
					success: function(e) {
						// #ifndef MP
						Vue.prototype.StatusBar = e.statusBarHeight;
						if (e.platform == 'android') {
							Vue.prototype.CustomBar = e.statusBarHeight + 50;
						} else {
							Vue.prototype.CustomBar = e.statusBarHeight + 45;
						};
						// #endif
				
						// #ifdef MP-WEIXIN
						Vue.prototype.StatusBar = e.statusBarHeight+2;
						let custom = wx.getMenuButtonBoundingClientRect();
						Vue.prototype.Custom = custom;
						Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
						// #endif		
				
						// #ifdef MP-ALIPAY
						Vue.prototype.StatusBar = e.statusBarHeight;
						Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
						// #endif
						
						console.log(Vue.prototype.StatusBar,Vue.prototype.CustomBar);
					}
				});
				
				uni.loadFontFace({
					global:true,
					family:'SSFY',
					source:'url("https://microfoot.cn/web/statics/font/AlimamaShuHeiTi-Bold.ttf")',
					success() {
						  console.log('success')
					  },
					  fail(res) {
					  	console.log(res)
					  }
				});
			},
			// 获取系统配置
			getConfig() {
				
			},
		}
	}
</script>

<style>
	@import "colorui/icon.css";
	@import "colorui/main.css";
	
	.font-title {
		font-family: "SSFY";
		font-style: normal;
		transition: .3s;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		font-weight: bold;
	}
</style>
